import jsonschema

from api.login import LoginAPI
from common.assertPackage import common_assert
# 创建测试类
class TestLoginAPI:
    # token属性
    token666 = None

    # 登录成功
    def test01_login_success(self):
        # 准备测试数据
        login_data = {
            "mobile": "13800000002",
            "password": "123456"
        }
        # 基于响应结果进行断言
        # 接口类实例化对象.被封装的接口方法(要传递的参数)
        response = LoginAPI().login(login_data)
        print(response.json())

        # 断言
        # assert response.status_code == 200
        # assert response.json().get("success") is True
        # assert response.json().get("code") == 10000
        # assert "成功" in response.text
        # common_assert(response)
        # # 提取关联数据
        # TestLoginAPI.token666 = response.json().get("data")
        # print(TestLoginAPI.token666)
        my_schema = {
            "type": "object",
            "properties": {
                "success": {"const": True},
                "code": {"const": 10000},
                "message": {"pattern": "成功"},
                "data": {"type": "string"}
            }
        }

        # 全量字段校验
        # jsonschema.validate(实际结果（json格式）, 预期结果)
        jsonschema.validate(response.json(), my_schema)

